<?php

	if($_GET['do']== 1){
		$pdo = new PDO('mysql:host=localhost;dbname=riris', 'root', '');
		$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
		$sql = "SELECT NIP,NAMA FROM dosen";
		$stmt = $pdo->prepare($sql);
		$stmt->execute();
		$_data = $stmt->fetchAll(PDO::FETCH_OBJ);
		
		$pdo->query("USE uwika_krs_alpha");

		$sql = "INSERT INTO dosen (nim_dosen, nip, nama)
		values (:nim_dosen, :nip, :nama ) ";

		
		foreach($_data as $_data_){
			$depan = substr($_data_->NIP,2,3).substr($_data_->NIP,-3,3);
			echo $depan;
			$sql2 = "SELECT nim_dosen FROM dosen";
			$stmt2 = $pdo->prepare($sql2);
			$stmt2->execute();
			$isi = $stmt2->rowCount()+1;
			if( $isi < 10 ){ $isi = '00'.$isi; }
			elseif( $isi < 100 ){ $isi = '0'.$isi;}
			echo $isi;
			var_dump($_data_);echo '<br \>';
			
			if( !empty($_data_->NAMA)) {
				$stmt = $pdo->prepare($sql);
				$stmt->execute(array(':nim_dosen' => $depan.$isi ,':nama' => $_data_->NAMA 
									,':nip' => $_data_->NIP
				)) or die("ERROR: " . implode(":", $stmt->errorInfo()));
			}
		}
	}
	


?>